{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "import ogr, gdal\n",
    "import numpy as np\n",
    "import glob\n",
    "import os,sys\n",
    "import osr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#https://gis.stackexchange.com/questions/254410/raster-to-vector-conversion-using-gdal-python\n",
    "\n",
    "fileName = \"/home/jovyan/data/wadnr/lidar/datasets/baker_2015/dsm/baker_2015_dsm_7.tif\"\n",
    "src_ds = gdal.Open(fileName)\n",
    "if src_ds is None:\n",
    "    print('Unable to open %s' % src_fileName)\n",
    "    sys.exit(1)\n",
    "srcband = src_ds.GetRasterBand(1)\n",
    "srs = osr.SpatialReference()\n",
    "srs.ImportFromWkt(src_ds.GetProjection())\n",
    "\n",
    "dst_layername = \"Full_raster2shp\"\n",
    "drv = ogr.GetDriverByName(\"GPKG\")\n",
    "dst_ds = drv.CreateDataSource(dst_layername + \".gpkg\")\n",
    "dst_layer = dst_ds.CreateLayer(dst_layername, srs = srs)\n",
    "#newField = ogr.FieldDefn('Area', ogr.OFTInteger)\n",
    "#dst_layer.CreateField(newField)\n",
    "gdal.Polygonize(srcband, None, dst_layer, 0, [], \n",
    "callback=None )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
